<template>
  <nav-bar>
    <div class="center" slot="center">
      <el-form :model="searchForm"
               status-icon
               ref="searchForm"
               label-width="0"
               class="searchForm">
        <el-form-item prop="search">
          <el-input type="search"
                    :placeholder="placeholder"
                    v-model="searchForm.searchInput"
                    autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('searchForm')">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
  </nav-bar>
</template>

<script>
  import NavBar from "components/content/navBar/NavBar";
  export default {
    name: "SearchNavBar",
    components: {
      NavBar
    },
    data() {
      return {
        searchForm: {
          searchInput: '',
        }
      }
    },
    computed: {
      placeholder() {
        let placeholder = '请输入关键词搜索'
        if(this.$route.path.indexOf('post') !== -1) {
          placeholder = '请输入职位名称搜索 如：Web前端工程师'
        }else if(this.$route.path.indexOf('firm') !== -1) {
          placeholder = '请输入公司名称搜索 如：百度'
        }else if(this.$route.path.indexOf('question') !== -1) {
          placeholder = '请输入题库相关关键词搜索 如：前端'
        }
        return placeholder
      }
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$bus.$emit('search', this.searchForm.searchInput)
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    }
  }
</script>

<style scoped>
  .center {
    width: 500px;
    margin: 12px 0 0 150px;
  }

  .el-form-item {
    float: left;
  }

  .searchForm >>> .el-input__inner {
    width: 400px;
    height: 40px;
    border-radius: 5px 0 0 5px;
    border-color: #fff;
  }

  .searchForm >>> .el-button {
    width: 80px;
    height: 40px;
    margin-left: -1px; /*解决搜索框和按钮之间的线条*/
    background-color: #fff;
    border-color: #fff;
    color: #002766;
    border-radius: 0 5px 5px 0;
  }
</style>
